<template>
    <div>
        <div>
            标题:<input type="text" v-model="tiao.Title">
            适用门店: <select v-model="tiao.DropId">
                <option value="">请选择</option>
                <option :value=1>昌平店</option>
                <option :value=2>顺义店</option>
                <option :value=3>北京总店</option>
            </select>
            <input type="button" value="查询" class="btn btn-primary" @click="show()">
        </div>
<table class="table table-bordered">
    <tr>
        <td>优惠券类型</td>
        <td>标题</td>
        <td>副标题</td>
        <td>图片</td>
        <td>剩余库存</td>
        <td>每人限领</td>
        <td>使用条件</td>
        <td>减免金额</td>
        <td>有效期</td>
        <td>适用业务</td>
        <td>使用须知</td>
        <td>适用门店</td>
        <td>服务电话</td>
        <td>操作</td>
    </tr>
    <tr v-for="item in info.list">
        <td>{{item.disType}}</td>
        <td>{{item.disTitle}}</td>
        <td>{{item.fuDisTitle}}</td>
        <td><img :src="item.photo" alt="" height="70px" width="70px"></td>
        <td>{{item.kuCunNum}}</td>
        <td>{{item.xianLing}}</td>
        <td>¥{{item.tiaoJianNum}}</td>
        <td>¥{{item.price}}</td>
        <td>{{item.createTime.substring(0,10)}}--{{ item.endsTime.substring(0,10) }}</td>
        <td>{{item.yeWu}}</td>
        <td>{{item.desc}}</td>
        <td>
            <span v-if="item.dropId==1">昌平店</span>
            <span v-if="item.dropId==2">顺义店</span>
            <span v-if="item.dropId==3">北京总店</span>
        </td>
        
        <td>{{item.phone.substring(0,3)}}****{{item.phone.substring(6)}}</td>
        <td>
            <input type="button" @click="dele(item.id)" value="删除" class="btn btn-primary">
            <input type="button" @click="upd(item.id)" value="修改" class="btn btn-primary">
        </td>
    </tr>
</table>
<div>
    <span>共{{info.count}}条</span>
    <span>每页{{tiao.size}}条</span>
    <span>共{{tiao.index}}/{{info.pagecount}}页</span>
    <input type="button" value="首页" @click="fan(1)" class="btn btn-primary">
    <input type="button" value="上一页" @click="fan(tiao.index-1)" class="btn btn-primary">
    <input type="button" value="下一页" @click="fan(tiao.index+1)" class="btn btn-primary">
    <input type="button" value="尾页" @click="fan(info.pagecount)" class="btn btn-primary">
</div>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref,reactive,onMounted } from 'vue';
import moment from 'moment';
import { useRoute,useRouter } from 'vue-router';
let router=useRouter();
let info:any=reactive({
    list:[],
    count:0,
    pagecount:0
});
let tiao:any=reactive({
    index:1,
    size:2,
    Title:'',
    DropId:''
});


////////////////////////////////函数///////////////////////////////////

onMounted(()=>{
    show();
})

//翻页
const fan=(i:any)=>{
if(i<0){
tiao.index=1
}else if(i>info.pagecount){
tiao.index=info.pagecount;
}else{
    tiao.index=i;
}
show();
}
//显示
const show=()=>{
    axios({
        url:'https://localhost:7074/api/Dis/GetDis',
        params:tiao,
        method:'get'
    })
    .then(res=>{
        console.log(tiao);       
        info.list=res.data.list;
        info.count=res.data.count;
        info.pagecount=res.data.pagecount;
    })
}
//删除
const dele=(id:any)=>{
    if(!confirm('确认删除吗?')){
return;
    }
axios({
    url:'https://localhost:7074/api/Dis/DeleDis',
    params:{id:id},
    method:'delete'
})
.then(res=>{
    if(res.data>0){
alert('删除成功');
show();
    }
})
}

//修改
const upd=(id:any)=>{
router.push({
    query:{id:id},
    path:'/upDis'
})
}
</script>

<style scoped>

</style>